package com.wzdigit.wms.wms.service.core.outbound;
/**
 * 拣货任务明细货品清单 服务类
 *
 * @Author:yangwenbiao
 * @Date 2021/2/26 4:06 PM
 * @version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.transfer.PicktaskDtlGoods;
import com.wzdigit.wms.basic.mapper.core.transfer.PicktaskDtlGoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class PicktaskDtlGoodsService {

    @Autowired
    PicktaskDtlGoodsMapper picktaskDtlGoodsMapper;

    /**
     * 添加一条记录
     * @param picktaskDtlGoods
     * @return
     */
    public Integer addOne(PicktaskDtlGoods picktaskDtlGoods) {
        int row = picktaskDtlGoodsMapper.insert(picktaskDtlGoods);
        return row;
    }


    /**
     * 根据拣货任务明细ID查询
     * @param picktaskDtlId
     * @return
     */
    public List<PicktaskDtlGoods> selectByPickDtlId(Integer picktaskDtlId) {

        //创建类型的条件构造器
        QueryWrapper<PicktaskDtlGoods> wrapper = new QueryWrapper<>();
        wrapper.eq("PICKTASK_DTL_ID", picktaskDtlId);
        List<PicktaskDtlGoods> picktaskDtlGoodsList = picktaskDtlGoodsMapper.selectList(wrapper);
        return picktaskDtlGoodsList;
    }

    /**
     * 根据goodsSN查询拣货清单表
     * @param sn
     * @return
     */
    public PicktaskDtlGoods selectByGoodsSnAndDtlIdHeadId(String sn,Integer dtlId,Integer headerId) {

        PicktaskDtlGoods picktaskDtlGoods = picktaskDtlGoodsMapper.selectByGoodsSnAndDtlIdHeadId(sn,dtlId,headerId);
        return picktaskDtlGoods;
    }

    /**
     * 根据SN查询，创建时间倒序，取第一条，即最新的一条
     * @param goodsSn
     * @return
     */
    public PicktaskDtlGoods selectLastByGoodsSn(String goodsSn) {
        //创建类型的条件构造器
        QueryWrapper<PicktaskDtlGoods> wrapper = new QueryWrapper<>();
        wrapper.eq("GOODS_SN", goodsSn);
        wrapper.orderByDesc("CREATE_TIME");

        List<PicktaskDtlGoods> picktaskDtlGoodsList = picktaskDtlGoodsMapper.selectList(wrapper);
        if (picktaskDtlGoodsList.size() == 0) {
            return null;
        }
        return picktaskDtlGoodsList.get(0);
    }

    public Integer deleteBySnList(List<String> goodsSnList) {
        //创建类型的条件构造器
        QueryWrapper<PicktaskDtlGoods> wrapper = new QueryWrapper<>();
        wrapper.in("GOODS_SN",goodsSnList);

        int deleteRow = picktaskDtlGoodsMapper.delete(wrapper);
        return deleteRow;
    }
}
